 /**
  * Class that extends TerminalOutput to differentiate terminal types
  * @class WireIt.util.WebUITerminalOutput
  * @extends WireIt.util.TerminalOutput
  * @constructor
  * @param {HTMLElement} parentEl Parent dom element
  * @param {Object} options configuration object
  * @param {WireIt.Container} container (Optional) Container containing this terminal
  * @author Igor Lazarev
  */
 
 WireIt.util.WebUITerminalOutput = function(parentEl, options, container) {
   WireIt.util.WebUITerminalOutput.superclass.constructor.call(this,parentEl, options, container);
  	if((this.container.options.title == "Script")||(this.container.options.title == "JavaScript")||(this.container.options.title == "Python")){
		var type = "string";
		var name = options.name;
		YAHOO.util.Event.addListener(this.el, "click", function(){
			var pos = YAHOO.util.Dom.getXY(this.el);
			var X = pos[0];
			var Y = pos[1];
			var containerConfig = '{"xtype":"WireIt.WebUIOutputContainer","title":"output","fields":[{"type": "myType", "inputParams": {"label": "Value", "name": "input", "wirable": false, "value": {"type": "' + "string" + '", "inputParams": {"name":"' + name + '","typeInvite": "input value"}}}}],"position":[' + (X - 290) + ',' + (Y) + ']}';
			var container = this.container.layer.addContainer(YAHOO.lang.JSON.parse(containerConfig));
			container.schema = portJSON;
			var outputTerminal = container.addTerminal({
				xtype: "WireIt.util.WebUITerminalInput",
				"name": name+":"+type,
				"ddConfig": {
					"type": "string"
				},
				"direction": [0, -1],
				"offsetPosition": {
					"left": 86,
					"top": -15
				}
			});
			container.setName(name);
			
			var wire = {
				"src": {
					"moduleId": WireIt.indexOf(this.container, this.container.layer.containers),
					"terminal": this.options.name
				},
				"tgt": {
					"moduleId": WireIt.indexOf(container, this.container.layer.containers),
					"terminal": outputTerminal.options.name
				},
				color:"rgb(240,191,186)"
			};
			this.container.layer.addWire(wire);
			this.redrawAllWires();
		}, this, true);
	}
	else if ((this.container.options.title != "input")&&(this.container.options.title != "Script")&&(this.container.options.title != "JavaScript")&&(this.container.options.title != "Python")) {
		var type = options.name.split(":")[1];
		var name = options.name.split(":")[0];
		var portJSON = this.container.resourceJSON.outputs[name];
		YAHOO.util.Event.addListener(this.el, "click", function(){
			var pos = YAHOO.util.Dom.getXY(this.el);
			var X = pos[0];
			var Y = pos[1];
			var containerConfig = '{"xtype":"WireIt.WebUIOutputContainer","title":"output","fields":[{"type": "myType", "inputParams": {"label": "Value", "name": "input", "wirable": false, "value": {"type": "' + options.name.split(":")[1] + '", "inputParams": {"name":"' + options.name.split(":")[0] + '","typeInvite": "input value"}}}}],"position":[' + (X - 290) + ',' + (Y) + ']}';
			var container = this.container.layer.addContainer(YAHOO.lang.JSON.parse(containerConfig));
			
			container.schema = portJSON;
			
			var termType = options.name.split(":")[1];
			var color = "rgb(173, 216, 230)";				
				
			if (termType=="string"){
				color = "rgb(239,224,95)";
			}
			else if (termType=="file"){
				color = "rgb(227,117,80)";
			}
			else if (termType=="boolean"){
				color = "rgb(107,95,59)";
			}
			else if (termType=="number"){
				color = "rgb(31,172,225)";
			}
			else if (termType=="integer"){
				color = "rgb(201,205,204)";
			}
			
			var outputTerminal = container.addTerminal({
				xtype: "WireIt.util.WebUITerminalInput",
				"name": options.name,
				"ddConfig": {
					"type": termType
				},
				"direction": [0, -1],
				"offsetPosition": {
					"left": 86,
					"top": -15
				}
			});
			container.setName(options.name.split(":")[0]);
			
			var wire = {
				"src": {
					"moduleId": WireIt.indexOf(this.container, this.container.layer.containers),
					"terminal": this.options.name
				},
				"tgt": {
					"moduleId": WireIt.indexOf(container, this.container.layer.containers),
					"terminal": outputTerminal.options.name
				},
				"color":color
			};
			this.container.layer.addWire(wire);
			this.redrawAllWires();
		}, this, true);
	}
  
};

YAHOO.lang.extend(WireIt.util.WebUITerminalOutput, WireIt.WebUITerminal, {
   
   /**
    * Override setOptions to add the default options for WebUITerminalOutput
    * @method setOptions
    */
   setOptions: function(options) {
      
      WireIt.util.WebUITerminalOutput.superclass.setOptions.call(this,options);
	  
	  this.options.direction = options.direction || [0,1];
	  this.options.fakeDirection = options.fakeDirection || [0,-1];
	  this.options.alwaysSrc = true;

	  var type = options.name.split(':')[1];
	  if (type){
		  this.options.ddConfig = {
			 type: "output:"+type,
			 allowedTypes: ["input:"+type,"input:script"]
      		}
	  }
   }
   
});
